CKEDITOR.dialog.add('smarttable', function(editor) {
	return {
		title: '表格管理',
		minWidth: 600,
		minHeight: 350,
		contents: [{
			id: 'info',
			elements: [{
				id: 'tabWidth',
				type: 'text',
				width: '60px',
				label: '高度',
				setup: function(widget) {
					var tabWidth = widget.data.tabWidth;
					if (tabWidth) {
						this.setValue(tabWidth);
					}
				},
				commit: function(widget) {
					widget.setData('tabWidth', this.getValue());
				}
			}, {
				type: 'hbox',
				widths: ['80%', '20%'],
				children: [{
					type: 'text',
					id: 'code',
					label: '脚本',
					validate: CKEDITOR.dialog.validate.notEmpty("脚本不能为空"),
					setup: function(widget) {
						var code = widget.data.code;
						if (code) {
							this.setValue(code);
						}
					},
					commit: function(widget) {
						widget.setData('code', this.getValue());
					}
				}, {
					id: 'preview',
					type: 'button',
					label: '预览',
					style: 'margin-top:14px',
					onClick: function() {
						var dialog = this.getDialog();
						var codeEle = dialog.getContentElement('info', 'code');
						SmartTable1.isChange = codeEle.isChanged();

						function doSome(data) {
							var exportTableData = SmartTable1.preview(data);
							$_doc.data(SmartTable1.tabId, {
								data: data,
								exportTableData: exportTableData
							});
						}
						if (SmartTable1.isChange) {
							var code = codeEle.getValue();
							ck.util.sendAjax({
								url: 'table/getTable',
								data: {
									pageId: pageId,
									code: code
								}
							}, doSome);
						} else {
							doSome($_doc.data(SmartTable1.tabId).data);
						}
					}
				}]
			}, {
				type: 'html',
				html: '<div id="tabPreview"><b>预览:</b><br/><div id="tabPreviewTable" style="width:600px;height:270px;border:1px solid rgb(138, 134, 134);overflow:auto;"></div></div>'
			}]
		}],
		onShow: function() {
			$('#tabPreviewTable table').remove();

			var editor = this.getParentEditor(),
				sel = editor.getSelection(),
				element = sel && sel.getSelectedElement();

			if (element) {
				SmartTable1.tabId = element.findOne('div.simplebox').getAttribute('data-tabid');
				SmartTable1.preview($_doc.data(SmartTable1.tabId).data);
			} else {
				SmartTable1.tabId = ck.util.randomString(16, 'aA');
			}
		},
		onOk: function() {
			smartTableOkSign = true;
		}
	};
});